import os
from datetime import timedelta

class BaseConfig:
    SECRET_KEY = os.getenv('SECRET_KEY', 'pear-admin-flask')

    SQLALCHEMY_DATABASE_URI = ""
    ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
    JWT_TOKEN_LOCATION = ["headers"] # [!code ++]
    JWT_ACCESS_TOKEN_EXPIRES = timedelta(days=7)  # [!code ++]


class DevelopmentConfig(BaseConfig):
    """开发配置"""
    SQLALCHEMY_DATABASE_URI = "sqlite:///pear_admin.db"
    SQLALCHEMY_TRACK_MODIFICATIONS = False


class TestingConfig(BaseConfig):
    """测试配置"""
    SQLALCHEMY_DATABASE_URI = 'sqlite:///:memory:'  # 内存数据库


class ProductionConfig(BaseConfig):
    """生成环境配置"""
    SQLALCHEMY_DATABASE_URI = "mysql://root:root@127.0.0.1:3306/pear_admin"
    SQLALCHEMY_TRACK_MODIFICATIONS = False


config = {
    'dev': DevelopmentConfig,
    'test': TestingConfig,
    'prod': ProductionConfig
}
